package com.yaorange.api;

import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.nongjt.dto.AuthParam;
import com.yaorange.nongjt.service.INjtSerialAuthService;
import com.yaorange.nongjt.service.INjtSerialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "序列号管理", tags = "序列号管理")
@RestController
@RequestMapping("/api/serial")
public class NjtSerialAPI {

    @Resource
    private INjtSerialService serialService;
    @Resource
    private INjtSerialAuthService serialAuthService;

    /**
     * 验证序列号是否已认证
     *
     * @param serialCode 序列号
     * @return 是否可以正常使用 字符串
     */
    @GetMapping("/checkSerialCode")
    @ApiOperation("验证序列号是否已认证")
    public AjaxResult checkSerialCode(@RequestParam("serialCode") String serialCode) {
        return serialService.checkSerialCode(serialCode);
    }

    @GetMapping("/querySerialAuthList")
    @ApiOperation("获取打印机列表")
    public AjaxResult querySerialAuthList() {
        return AjaxResult.success(serialAuthService.getSerialAuthList());
    }

    @GetMapping("/querySerialNoFlagList")
    @ApiOperation("获取未认证打印机列表")
    public AjaxResult querySerialNoFlagList() {
        return AjaxResult.success(serialAuthService.querySerialNoFlagList());
    }

    @PostMapping("/serialAuth")
    @ApiOperation("打印机序列号认证")
    public AjaxResult serialAuth(@RequestBody AuthParam authParam) {
        return serialAuthService.executeAuth(authParam.getSerialCode(), authParam.getMacCode());
    }
}

